package com.chance.cc.crawler.development.bootstrap.sn;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRecord;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

/**
 * @ClassName suning
 * @Description TODO
 * @Author SNStart
 * @Date 2021/10/18 16:54
 * @Version 1.0
 *苏宁 关键词查询
 **/
public class SNStart {
    public static final String domain = "suning";

    public static void main(String[] args) {
        auto();
    }

    public static void auto(){
        String site = "search";
        String url = "https://search.suning.com/";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*50,null))
                .needWashed(false)
                .needParsed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);

        record.setDownload(false);
        record.setSkipPipeline(true);

        //record.tagsCreator().bizTags().addCustomKV("q","adidas");

        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/suning/keys?site=searchKw")
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                .build();

        CrawlerRecord filterRecord = new CrawlerRecord();
        filterRecord.setFilter(CrawlerEnum.CrawlerRecordFilter.dateRange);
        filterRecord.addFilterInfo(FilterUtils.dateRangeFilterInfo(24,null));
        record.tagsCreator().bizTags().addCustomKV("comment_record_filter_info", JSON.toJSONString(filterRecord));

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .supportRecord(keywordRecord)
                .requestRecord(record)
                .build("com.chance.cc.crawler.development.scripts.sn")
                .start();
    }
}
